﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Syndication;
using System.Xml;

namespace RssReader
{
    public class FeedReader
    {
        public SyndicationFeed GetSyndicationFeed(string uri)
        {

            SyndicationFeed tracFeed;

            //string user = "enr";
            //string password = "enr";

            System.Net.WebClient wc = new System.Net.WebClient();

            //wc.Credentials = new System.Net.NetworkCredential(user, password);

            //this works!
            //string web = wc.DownloadString("http://trac:8080/project/login/xmlrpc");

            //this gives a 403 forbidden !! :-(
            System.IO.Stream webClientStream = wc.OpenRead(uri);
            //System.IO.Stream webClientStream = wc.OpenRead("http://feedproxy.google.com/oneindia-thatsmalayalam-news");

            try
            {

                using (XmlReader reader = XmlReader.Create(webClientStream))
                {
                    tracFeed = SyndicationFeed.Load(reader);
                }
            }
            catch (Exception ex)
            {
                //todo: need to handle this.

                throw ex;
            }
            finally
            {
                webClientStream.Close();
            }

            return tracFeed;
        }

    }
}
